//封装微信的请求
const BaseUrl = 'https://www.baidu.com'
function get(url) {
    wx.showLoading({
        title: '网络请求中',
        mask: true
    })
    return new Promise((resolve,reject) => {
        wx.request({
            url: `${BaseUrl}`,
            header: {'content-type':'application/json'},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: result => {
                resolve(result)
                console.log('result: ', result);
                wx.hideLoading()
            },
            fail: err => {
                reject(err)
                console.log('err: ', err);
                wx.hideLoading()
            },
            complete: () => {}
        })
    })
}

function post(url,params) {
    wx.showLoading({
        title: '网络请求中',
        mask: true
    })
    return new Promise((resolve,reject) => {
        wx.request({
            url: `http://localhost:7000/api/v3/basics`,
            data: {
                get: 'uptime'
            },
            header: {'content-type':'application/json'},
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: result => {
                resolve(result)
                wx.hideLoading()
            },
            fail: err => {
                reject(err)
                wx.hideLoading()
            },
            complete: () => {}
        })
    })
}

module.exports = {
    get,
    post
}